package java.lang;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ObjectTest {
    //直接在自定义java.lang.Object下面创建main方法会报找不到main方法错误，因为加载的Object是系统类lib下面的，所以这里新建一个ObjectTest去执行main方法
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Object obj = new Object();
        // 编译报错
//        obj.mySelfMethod();
        // 反射获取
        Class<?> objClz = Class.forName("java.lang.Object");
        Object objOne = objClz.newInstance();
        Method mySelfMethod = objClz.getMethod("mySelfMethod");
        // java.lang.NoSuchMethodException: java.lang.Object.mySelfMethod()
        mySelfMethod.invoke(objOne);
    }
}
